package cn.wilson.hrm.feign.fallback;


import cn.wilson.hrm.doc.CourseDoc;
import cn.wilson.hrm.feign.client.EsFeignClient;
import cn.wilson.hrm.query.CourseQuery;
import cn.wilson.hrm.utils.AjaxResult;
import cn.wilson.hrm.utils.PageList;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

//调用es服务的托底类
@Component
public class EsFeignClientFallbackFactory implements FallbackFactory<EsFeignClient> {
    @Override
    public EsFeignClient create(Throwable throwable) {


        return new EsFeignClient(){

            @Override
            public AjaxResult save(CourseDoc courseDoc) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("es服务暂停使用");
            }

            @Override
            public AjaxResult offline(CourseDoc courseDoc) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("es服务暂停使用");
            }

            @Override
            public PageList<CourseDoc> searchCourse(CourseQuery courseQuery) {
                throwable.printStackTrace();
                return new PageList<>(-1,new ArrayList<>());
            }
        };
    }
}
